<%
   @post_type = current_site.post_types.new if @post_type.nil?
   groups = @post_type.get_field_groups({kind: "post_type"})
%>
<%= form_for @post_type, as: "post_type", url:{action: @post_type.new_record? ? :create : :update} , html:{class: 'validate-post-type zerocms_ajax_request', id: "post_type_form"} do |f| %>
    <%= f.hidden_field :parent_id  %>
    <%= f.hidden_field :taxonomy %>
    <div class="panel-body">
      <%= render partial: 'layouts/zerocms/admin/form_error', locals: {data: @post_type} %>
        <div class="form-group">
          <%= f.label t('zerocms.admin.table.name') %><br>
          <%= f.text_field :name, :class => "form-control required translatable" %>
        </div>
        <div class="form-group">
            <%= f.label t('zerocms.admin.table.slug') %><br>
            <%= f.text_field :slug, :class => "form-control slug no_translate required", "data-parent" => "post_type_name" %>
        </div>

        <div class="form-group">
          <%= f.label t('zerocms.admin.table.description') %><br>
          <%= f.text_area :description, :class => "form-control translatable", :rows => 4 %>
        </div>

        <div class="form-group">
            <label><%= t('zerocms.admin.post_type.icon', default: 'Icon') %></label>
            <%= text_field_tag "meta[icon]", @post_type.get_option("icon", ''), class: 'form-control', placeholder: 'dashboard' %>
            <small><%= t('zerocms.admin.post_type.icons_url_desc', default: 'Please enter any icon name from here: ') %> https://fortawesome.github.io/Font-Awesome/icons/</small>
        </div>
        <%= args={html: '', post_type: @post_type}; hooks_run('post_type_settings_form', args); raw(args[:html]) %>
        <hr/>
        <h4><%= t('zerocms.admin.table.settings') %></h4>

        <!-- Settings -->
        <div>
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#post_type_setting_admin" aria-controls="profile" role="tab" data-toggle="tab"><%= t("zerocms.admin.post_type.back_settings", default: "Admin") %></a></li>
                <li role="presentation"><a href="#post_type_setting_front" aria-controls="home" role="tab" data-toggle="tab"><%= t("zerocms.admin.post_type.front_settings", default: "Visitor") %></a></li>
                <% if groups.present? %>
                    <li role="presentation"><a href="#post_type_setting_custom" aria-controls="messages" role="tab" data-toggle="tab"><%= t("zerocms.admin.post_type.front_settings", default: "Custom") %></a></li>
                <% end %>
            </ul>
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane active" id="post_type_setting_admin">
                    <div class="form-group">
                        <input name="meta[has_layout]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_layout]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_layout') %>/>&nbsp;   <%= t('zerocms.admin.table.manage_layout') %></label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_manage_layout')}", 'right') %>
                    </div>
                    <div class="form-group">
                        <label><%= t('zerocms.admin.post_type.default_layout') %> <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.default_layout')}", 'right') %></label>
                        <%= select("meta", "default_layout", zerocms_get_list_layouts_files(@post_type), { include_blank: true, selected: @post_type.get_option("default_layout") }, {class: 'form-control'}) %>
                    </div>

                    <div class="form-group">
                        <input name="meta[has_template]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_template]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_template', true) %>/>&nbsp;   <%= t('zerocms.admin.table.manage_template') %></label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_manage_template')}", 'right') %>
                    </div>
                    <div class="form-group">
                        <label><%= t('zerocms.admin.post_type.default_template') %> <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.default_template')}", 'right') %></label>
                        <%= select("meta", "default_template", zerocms_get_list_template_files(@post_type), { include_blank: true, selected: @post_type.get_option("default_template") }, {class: 'form-control'}) %>
                    </div>


                    <div class="form-group">
                        <input name="meta[has_category]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_category]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_category', false) %>/>&nbsp;   <%= t('zerocms.admin.table.manage_category') %></label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_asing_categories')}", 'right') %>
                    </div>
                    <div class="form-group">
                        <input name="meta[has_tags]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_tags]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_tags', false) %>/>&nbsp;   <%= t('zerocms.admin.table.manage_tags') %>
                        </label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_add_tags')}", 'right') %>
                    </div>
                    <div class="form-group">
                        <input name="meta[has_content]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_content]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_content', true) %>/>&nbsp;   <%= t('zerocms.admin.table.manage_content') %>
                        </label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_add_content')}", 'right') %>
                    </div>
                    <div class="form-group">
                        <input name="meta[has_summary]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_summary]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_summary', true) %>/>&nbsp;   <%= t('zerocms.admin.table.manage_summary') %>
                        </label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_add_content_summary')}", 'right') %>
                    </div>
                    <div class="form-group">
                        <input name="meta[has_comments]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_comments]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_comments', true) %>/>&nbsp;   <%= t('zerocms.admin.table.permit_comments_default') %>
                        </label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_reviews')}", 'right') %>
                    </div>
                    <div class="form-group">
                        <input name="meta[has_featured]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_featured]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_featured', false) %>/>&nbsp;   <%= t('zerocms.admin.table.permit_is_featured', default: 'Permit Featured Articles') %></label>
                    </div>
                    <div class="form-group">
                        <input name="meta[has_seo]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_seo]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.manage_seo? %>/>&nbsp;   <%= t('zerocms.admin.table.manage_seo') %></label>
                    </div>
                    <div class="form-group">
                        <input name="meta[has_parent_structure]" type="hidden" value="false"/>
                        <label class="check0"><input name="meta[has_parent_structure]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.manage_hierarchy? %>/>&nbsp;   <%= t('zerocms.admin.table.manage_parent_structure', default: 'Manage page hierarchy') %></label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_to_support_parent_structure', default: "Permit to posts indicate the parent page")}", 'right') %>
                    </div>
                    <div class="form-group">
                        <input name="meta[has_picture]" type="hidden" value="false"/>
                        <label class="check0">
                            <input name="meta[has_picture]" type="checkbox" class="icheckbox0" value="true" <%= 'checked' if @post_type.get_option('has_picture', true) %>/>&nbsp;   <%= t('zerocms.admin.table.manage_picture') %>
                        </label>
                        <%= raw zerocms_html_tooltip("#{t('zerocms.admin.post_type.tooltip.permission_add_image_presentation')}", 'right') %>
                    </div>
                    <div class="picture_settings" style="margin-left: 30px">
                        <div class="form-group">
                            <label><%= zerocms_t('zerocms.admin.custom_field.fields.image_dimension') %></label>
                            <%= raw zerocms_html_tooltip("#{zerocms_t('zerocms.admin.custom_field.fields.image_dimension_descr')}", 'right') %>
                            <%= text_field_tag 'meta[posts_image_dimension]', @post_type.get_option('posts_image_dimension'), class: 'form-control' %>
                        </div>
                        <div class="form-group">
                            <label><%= zerocms_t('zerocms.admin.custom_field.fields.image_versions') %></label>
                            <%= raw zerocms_html_tooltip("#{zerocms_t('zerocms.admin.custom_field.fields.image_versions_descr')}", 'right') %>
                            <%= text_field_tag 'meta[posts_thumb_versions]', @post_type.get_option('posts_thumb_versions'), class: 'form-control' %>
                        </div>
                        <div class="form-group">
                            <label><%= zerocms_t('zerocms.admin.custom_field.fields.image_thumb') %></label>
                            <%= raw zerocms_html_tooltip("#{zerocms_t('zerocms.admin.custom_field.fields.image_thumb_descr', d: current_site.get_option('filesystem_thumb_size', '100x100'))}", 'right') %>
                            <%= text_field_tag 'meta[posts_thumb_size]', @post_type.get_option('posts_thumb_size'), class: 'form-control' %>
                        </div>
                        <div class="form-group">
                            <input name="meta[is_required_picture]" type="hidden" value="false"/>
                            <label class="check0"><%= check_box_tag 'meta[is_required_picture]', true, @post_type.get_option('is_required_picture', false) %> <%= zerocms_t('zerocms.admin.custom_field.fields.required_image_thumb') %></label>
                        </div>
                    </div>
                    <%= args={html: '', post_type: @post_type}; hooks_run('post_type_settings_admin', args); raw(args[:html]) %>
                </div>
                <div role="tabpanel" class="tab-pane" id="post_type_setting_front">
                    <div class="form-group">
                        <label><%= t('zerocms.admin.post_type.route_format') %></label>
                        <div>
                            <% @post_type.contents_route_formats.each do |key, descr| %>
                                <label><%= radio_button_tag "meta[contents_route_format]", key, key == @post_type.contents_route_format %> <small style="font-weight: normal"><%= raw descr %></small></label><br>
                            <% end %>
                        </div>
                    </div>
                    <div class="form-group">
                        <label><%= t('zerocms.admin.table.default_thumbnail') %></label><br>
                        <%= hidden_field :meta, :default_thumb, :class => "form-control unput_upload", :value => @post_type.get_option('default_thumb') %>
                    </div>
                </div>
                <% if groups.present? %>
                    <div id="post_type_setting_custom">
                        <%= render partial: "zerocms/admin/settings/custom_fields/render", locals: {record: @post_type, field_groups: groups} %>
                    </div>
                <% end %>
                <%= args={html: '', post_type: @post_type}; hooks_run('post_type_settings_front', args); raw(args[:html]) %>
            </div>
        </div>
    </div>

    <div class="panel-footer">
      <a class="btn btn-default" role="back" href="<%= url_for action: :index %>"><%= t('zerocms.admin.button.back') %></a>
      <button class="btn btn-primary pull-right" type="submit"><%= t('zerocms.admin.button.submit') %></button>
    </div>
<% end %>
<script>
    jQuery(function($){ zerocms_init_posttype_form(); });
</script>

